package com.example.newproject_overseas.Screen


import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.example.newproject_overseas.ViewModel.OrderDetailsViewModel
import com.example.newproject_overseas.components.Product_7_WhiteBox
import com.example.newproject_overseas.components.TopNoBackApp

@Composable
fun ProductList_7(navController: NavHostController) {
    val screenWidth = LocalConfiguration.current.screenWidthDp//屏幕宽度
    val screenHeight = LocalConfiguration.current.screenHeightDp//屏幕宽度 只是高度 数值没单位
    var sourceElementHeight by remember { mutableStateOf(0) }// lazycolumn的高度
    var elementHeight by remember { mutableStateOf(0) } //底部按钮的高度
    //相当于onload
    LaunchedEffect(elementHeight, screenHeight) {
        sourceElementHeight = screenHeight - 45 - elementHeight +65//lazycolumn的高度
    }
    //封装好的数据带过来
    val OrderDetailsViewModel: OrderDetailsViewModel = viewModel()
    Box(
        modifier = Modifier
            .fillMaxSize()
            .background(color = Color(0xffEFF0F3))

    ) {
        Column(modifier = Modifier) {
            TopNoBackApp("Product List")

            Column(modifier = Modifier.height(sourceElementHeight.dp)) {
                LazyColumn() {
                    items(OrderDetailsViewModel.product_7List) { item ->
                        Product_7_WhiteBox(item)
                    }
                }
            }
        }
                Button(
                    onClick = {
                        Log.i(
                            "qweqweqwe",
                            "${screenHeight}-${elementHeight}-${sourceElementHeight}"
                        )
                    },
//            enabled = LoginViewModel.radioButtonValue,
                    colors = ButtonDefaults.buttonColors(
                        backgroundColor = Color(0xffFFCC00),
                        contentColor = Color.White
                    ),
                    modifier = Modifier
                        .fillMaxWidth()
                        .align(Alignment.BottomCenter)
                        .onGloballyPositioned { coordinates ->
                            elementHeight = coordinates.size.height
                        },
                    shape = RectangleShape //设置形状为矩形
                ) {
                    Row(verticalAlignment = Alignment.CenterVertically) {
                        Text(
                            text = "Submit",
                            modifier = Modifier.weight(1f),
                            textAlign = TextAlign.Center,
                            fontSize = 20.5.sp,
                        )
                    }
                }
    }
}

@Preview
@Composable
fun ProductList_7Preview() {
    val navController = rememberNavController() // 假设这里使用了导航控制器
    ProductList_7(navController)
}
